<template>
	<!-- 我的/我的发布详情页 -->
	<view>

		<view class="custom_top" :style="{height:top_height+45+'px'}">

			<view @click="toback" class="back">
				<u-icon name="arrow-left" color="#ffffff" size="36"></u-icon>
			</view>

			<!-- <label class="iconMoney icons iconarrow-left" @click="toback"></label> -->
			<!-- <text>我的招工信息</text> -->
		</view>


		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change"
					:is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			</view>
			<view v-if="type == 0" class="sticky">
				免费发布招工信息让工人主动联系您
				<u-button @click="publish(1)" class="btn" size="mini" plain type="warning">
					发布招工
				</u-button>
				<u-button @click="recruit" class="btn" size="mini" plain type="warning">
					发布招聘
				</u-button>
			</view>
			<view v-else class="sticky">
				免费发布二手交易<u-button @click="publish(2)" class="btn" size="mini" plain type="warning">发布二手交易</u-button>
			</view>

			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item :key="index" v-for="(item, index) in list" class="swiper-item">
					<scroll-view scroll-y style="height: 100%; width: 100%" @scrolltolower="reachBottom">
						<view class="page-box">
							<view class="order">
								<u-empty class="empty" v-if="orderList[index].length == 0" text="暂无数据" mode="list">
								</u-empty>

								<view v-if="type">
									<trade @refrash="refrash" :list="orderList[index]" />
								</view>

								<view v-else>
									<recruitmentItem @refrash="refrash" :list="orderList[index]" />
								</view>

								<u-loadmore v-show="showBox" :status="loadStatus[index]" icon-type="flower"
									margin-bottom="30" />
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<choiceCateType v-if="mask" :companyInfo="companyInfo" urls="/package/pages/release/recruitment" reload="1" @hideMask="hideMask" />
		<!-- <choiceCateType v-if="mask"  reload="1" @hideMask="hideMask" /> -->
	</view>
</template>

<script>
	import recruitmentItem from "./recruitmentItem.vue";
	import trade from "./trade.vue";
	import empty from "@/components/empty/empty.vue";
	import choiceCateType from "@/components/choiceCateType.vue";
	import api from "../../../../api/routes.js";
	export default {
		components: {
			recruitmentItem,
			trade,
			empty,
			choiceCateType,
		},

		data() {
			return {
				top_height: 0,
				mask: false,
				type: 0,
				limit: 8,
				showBox: false,
				orderList: {
					0: [],
					1: [],
				},
				pages: [1, 1],

				list: [{
						name: "我的招工",
					},
					{
						name: "我的二手交易",
					},
				],
				companyInfo:[],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ["loadmore", "loadmore"],
			};
		},
		onLoad() {
			this.getOrderList(0);
			this.getCompanyInfo();

			let that = this;
			uni.getSystemInfo({
				success(res) {
					that.top_height = res.statusBarHeight; //data中 声明 top_height:0 
				}
			});
		},


		methods: {
			// 获取公司信息
			async getCompanyInfo(){
				const res = await this.$myRequest({
				  url: api.companyInfo,
				  method: "GET",
				  data: {},
				});
				if(res.data.code==0){
					this.companyInfo=JSON.stringify(res.data.company);
				}
				console.log(this.companyInfo,'公司信息');
			},
			//methods方法
			toback() {
				uni.switchTab({
					url: "/pages/my/my"
				})
			},
			hideMask(val) {

				this.mask = false;
				// uni.navigateTo({
				// 	url: `/package/pages/release/recruitment?companyData=`+this.companyInfo,
				// });
			},
			refrash(val) {

				this.orderList[val] = [];
				this.pages[val] = 1;
				this.getOrderList(val);
			},
			publish(type) {
				if (type == 1) {
					this.mask = true;
				} else {
					uni.navigateTo({
						url: `/package/pages/release/secondHand`,
					});
				}
			},
			recruit(){
				 // let company=JSON.stringify(this.companyInfo)
				uni.navigateTo({
					url: `/package/pages/release/recruitment?companyData=`+this.companyInfo +'&type=local',
				});
				console.log(this.companyInfo,"跳转company");
			},
			reachBottom() {
				// 此tab为空数据

				if (
					this.loadStatus[this.current] == "loading" ||
					this.loadStatus[this.current] == "nomore"
				) {
					return;
				}
				this.getOrderList(this.current);
			},
			// 页面数据
			async getOrderList(idx) {
				console.log(idx);

				const res = await this.$myRequest({
					url: idx == 0 ? api.pageMyJobList : api.pageMySecondBuyList,
					method: "POST",
					data: {
						page: this.pages[idx],
						limit: this.limit,
					},
				});
				console.log(res,'发布招工！！！');

				if (res.data.code == 0) {
					this.showBox = true;

					let data = res.data.page.list;
					if (data.length < this.limit) {
						this.loadStatus[this.current] = "nomore";
					} else {
						this.pages[this.current] = this.pages[this.current] + 1;
						this.loadStatus[this.current] = "loadmore";
					}
					this.orderList[idx] = this.orderList[idx];
					this.orderList[this.current] = [
						...this.orderList[this.current],
						...data,
					];

					if (idx == 0) {
						if (this.orderList[0] == 0) {
							this.showBox = false
						} else {
							this.showBox = true
						}
					} else {
						if (this.orderList[1] == 0) {
							this.showBox = false
						} else {
							this.showBox = true
						}
					}

					console.log(this.orderList,'this.orderList');
					uni.stopPullDownRefresh();
				}
			},

			// tab栏切换
			change(index) {
				this.type = index;
				this.swiperCurrent = index;
				this.orderList[index] = [];
				this.pages[index] = 1;

				this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				this.type = current;
				this.orderList[current] = [];
				this.pages[current] = 1;
				this.getOrderList(current);
			},
		},
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.empty {
		display: block;
		margin: 100px 0 0;
	}

	.sticky {
		display: flex;
		align-items: center;
		background-color: #fffaf4;
		color: #f9aa45;
		padding: 15rpx 32rpx;
		font-size: 13px;

		.btn {
			margin: 0 20rpx;
		}
	}

	.order {
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}
			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}

			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}

	.custom_top {
		background: #1684FC;
		display: flex;
		align-items: center;
		padding-top: 30px;
		justify-content: center;
		color: #FFFFFF;
		font-size: 12px;
		position: relative;
	}

	.back {
		position: absolute;
		left: 10px;
		top: 50px;
		width: 40px;
		height: 40px;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
